import sys

from PyQt5.QtGui import QPixmap
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QLineEdit, QPushButton, QFrame, QVBoxLayout, QHBoxLayout, \
    QCheckBox, QSlider, QProgressBar

'''
self.lbm = QLabel('图片', self)
self.lbm.setPixmap(QPixmap("./img/liu.jpg"))
self.lbm.resize(350, 230)
self.lbm.setScaledContents(True)
'''


class MyClass(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        self.setWindowTitle('刘金玉编程')
        self.setGeometry(800, 370, 400, 300)

        self.lbm = QLabel('图片', self)
        self.pm = QPixmap("./img/liu.jpg")
        self.lbm.setPixmap(self.pm)
        self.lbm.resize(350, 230)
        self.lbm.setScaledContents(True)  # 图片自动适应大小
        self.lbm.move(25, 0)

        btn1 = QPushButton('显示图片', self)
        btn1.clicked.connect(self.myAddPic)
        btn2 = QPushButton('移除图片', self)
        btn2.clicked.connect(self.myRemovePic)
        btn1.move(50, 240)
        btn2.move(50, 265)

        self.show()

    def myRemovePic(self):
        self.lbm.setPixmap(QPixmap(''))

    def myAddPic(self):
        self.lbm.setPixmap(self.pm)


if __name__ == '__main__':
    app = QApplication(sys.argv)
    myf = MyClass()
    app.exec_()
